function getRecentDate(num) {
  let d = Date.now(), res = [];
  for(let i = 0; i < num; i++) {
    res.push(new Date(d - i * 24 * 60 * 60 * 1000))
  }
  res.reverse();
  return res;
}

function format(date, pattern) {
  if(!(date instanceof Date) && typeof date !== 'number') {
    console.error(`date formate: date-${date} is not a instance of Date or number, return empty string`);
    return "";
  }
  if(typeof date === 'number') date = new Date(date);
  if(!pattern || !(typeof pattern === 'string')) {
    return date.toLocaleString();
  } else  {
    return pattern.replace("yyyy", date.getFullYear())
    .replace('MM', date.getMonth() + 1)
    .replace('dd', date.getDate())
    .replace('HH', date.getHours())
    .replace('mm', date.getMinutes())
    .replace('ss', date.getSeconds());
  }
}

export default {
  getRecentDate,
  format
}